package com.tsing.cedap.rest.controller;

import com.tsing.cedap.common.annotations.PassToken;
import com.tsing.cedap.common.annotations.SystemLog;
import com.tsing.cedap.common.utils.ResultUtil;
import com.tsing.cedap.common.valid.AddGroup;
import com.tsing.cedap.common.valid.UpdateGroup;
import com.tsing.cedap.common.vo.BasePageVo;
import com.tsing.cedap.common.vo.PageResult;
import com.tsing.cedap.common.vo.ResultData;
import com.tsing.cedap.rest.service.IMiniAboutMeService;
import com.tsing.cedap.rest.vo.reqVo.CodeReqVo;
import com.tsing.cedap.rest.vo.reqVo.MiniUpdateAddressReqVo;
import com.tsing.cedap.rest.vo.reqVo.TradeReqVo;
import com.tsing.cedap.rest.vo.respVo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * @author TheTsing
 * @create 2022-01-27 9:37
 */
@Api(tags = "小程序关于我的模块")
@RestController
@RequestMapping("/aboutMe")
public class MiniAboutMeController {

    @Autowired
    private IMiniAboutMeService miniAboutMeService;

    @GetMapping("/miniUserInfo")
    @ApiOperation(value = "小程序获取用户信息")
    @SystemLog(description = "小程序获取用户信息")
    public ResultData<MiniGetUserInfoRespVo> miniUserInfo(HttpServletRequest request) {
        return ResultUtil.success(miniAboutMeService.miniUserInfo(request));
    }

    @GetMapping("/miniGetBalance")
    @ApiOperation(value = "我的钱包余额")
    @SystemLog(description = "我的钱包余额")
    public ResultData<MiniGetBalanceRespVo> miniGetBalance(HttpServletRequest request) {
        return ResultUtil.success(miniAboutMeService.miniGetBalance(request));
    }

    @GetMapping("/miniGetAccountPage")
    @ApiOperation(value = "账户流水分页")
    @SystemLog(description = "账户流水分页")
    public ResultData<PageResult<MiniGetAccountPageRespVo>> miniGetAccountPage(@Validated BasePageVo reqVo, HttpServletRequest request) {
        return ResultUtil.success(miniAboutMeService.miniGetAccountPage(reqVo, request));
    }

    @GetMapping("/miniGetAddressPage")
    @ApiOperation(value = "常用地址分页")
    @SystemLog(description = "常用地址分页")
    public ResultData<PageResult<MiniGetAddressPageRespVo>> miniGetAddressPage(@Validated BasePageVo reqVo, HttpServletRequest request) {
        return ResultUtil.success(miniAboutMeService.miniGetAddressPage(reqVo, request));
    }

    @GetMapping("/miniGetAddressById")
    @ApiOperation(value = "获取单个地址")
    @SystemLog(description = "获取单个地址")
    public ResultData<MiniGetAddressByIdRespVo> miniGetAddressById(@Validated CodeReqVo reqVo) {
        return ResultUtil.success(miniAboutMeService.miniGetAddressById(reqVo));
    }

    @PostMapping("/miniAddAddress")
    @ApiOperation(value = "新增地址")
    @SystemLog(description = "新增地址")
    public ResultData<String> miniAddAddress(@Validated({AddGroup.class}) @RequestBody MiniUpdateAddressReqVo reqVo, HttpServletRequest request) {
        return ResultUtil.success(miniAboutMeService.miniAddAddress(reqVo, request));
    }

    @PostMapping("/miniUpdateAddress")
    @ApiOperation(value = "修改地址")
    @SystemLog(description = "修改地址")
    public ResultData miniUpdateAddress(@Validated({UpdateGroup.class}) @RequestBody MiniUpdateAddressReqVo reqVo, HttpServletRequest request) {
        miniAboutMeService.miniUpdateAddress(reqVo, request);
        return ResultUtil.success();
    }

    /**
     * 支付宝PC网页支付
     */
    @PostMapping("/toPayAsPC")
    @ApiOperation(value = "支付宝PC网页支付")
    @SystemLog(description = "支付宝PC网页支付")
    public ResultData<String> toPayAsPc(@Validated @RequestBody TradeReqVo reqVo, HttpServletRequest request) {
        // 买家账号 nfbroi6638@sandbox.com
        // 买家密码 111111
        return ResultUtil.success(miniAboutMeService.toPayAsPc(reqVo, request));
    }

    /**
     * 支付宝PC网页支付
     */
    @PostMapping("/toPayAsPhone")
    @ApiOperation(value = "支付宝手机支付")
    @SystemLog(description = "支付宝手机支付")
    public ResultData<String> toPayAsPhone(@Validated @RequestBody TradeReqVo reqVo, HttpServletRequest request) {
        // 买家账号 nfbroi6638@sandbox.com
        // 买家密码 111111
        return ResultUtil.success(miniAboutMeService.toPayAsPhone(reqVo, request));
    }

    /**
     * 支付异步通知（要公网访问）对外隐藏此接口，且不需要权限
     */
    @PassToken
    @ApiIgnore
    @RequestMapping("/aliPayNotify")
    @SystemLog(description = "支付异步通知")
    public String aliPayNotify(HttpServletRequest request) {
        return miniAboutMeService.aliPayNotify(request);
    }
}
